//
//  XMLDocumentFromURL.m
//  XMLTest
//
//  Created by  ibokan on 10-9-21.
//  Copyright 2010 tencent.com. All rights reserved.
//

#import "SendHttpRequest.h"


@implementation SendHttpRequest

+(NSString *) sendHttpPostRequestWithURLString: (NSString *) httpUrl postString: (NSString *)postString decodeEncoding: (NSStringEncoding) decodeEncoding
{
	NSData *postData = [postString dataUsingEncoding: NSUTF8StringEncoding allowLossyConversion: YES];
	NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
	NSURL *baseUrl = [NSURL URLWithString: httpUrl];
    NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL: baseUrl
                                                              cachePolicy: NSURLRequestReloadIgnoringCacheData 
                                                          timeoutInterval: 5.0];
    [urlRequest setHTTPMethod: @"POST"];
	[urlRequest setHTTPBody: postData];
    [urlRequest setValue: postLength forHTTPHeaderField:@"Content-Length"];
	
	NSError *error = nil;
    NSURLResponse *response = nil;
	
    NSData *urlData = [NSURLConnection 
                       sendSynchronousRequest:urlRequest 
                       returningResponse: &response 
                       error: &error];
	
	NSString *responseString = [[[NSString alloc] initWithData:urlData encoding: decodeEncoding] autorelease];
		
	
	
	return responseString;
}



@end
